package com.yu.controller;

import com.alibaba.fastjson.JSON;
import com.yu.pojo.Result;
import com.yu.utils.AliOSSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

//    @PostMapping("/upload")
//    public void upload(String username, Integer age, MultipartFile image){ // TODO:MultipartFile获取文件
//        System.out.println("username = " + username);
//        System.out.println("age = " + age);
//        System.out.println("image = " + image);
//    }

    @PostMapping("/upload")
    public String upload(MultipartFile image) throws IOException {
        String url = aliOSSUtils.upload(image);
        Result result = Result.success(url);
        return JSON.toJSONString(result);
    }
}
